<template>
  <view style="height: 100%;">
    <uni-popup ref="popup" type="bottom">
      <ad unit-id="adunit-5b435bd016a10838" ad-type="video" ad-theme="white"></ad>
    </uni-popup>
    <!-- 资源位置 -->
    <view class="goods-item" v-for="(item,i) in goods" :key="i" v-show="pageJson.tag=='洛丽塔'?1:0">
      <!-- 左侧图片区域 -->
      <view class="goods-item-left">
        <image :src="item.goods_small_logo" class="goods-pic"></image>
      </view>
      <!-- 右侧信息区域 -->
      <view class="goods-item-right">
        <!-- 商品标题 -->
        <view class="goods-name">{{item.goods_name}}</view>
        <view class="goods-info-box">
          <!-- 商品价格 -->
          <view class="goods-price">
            <uni-link :href="item.goods_price" text="点击进行复制链接" showUnderLine="true" color="#fa1365" font-size="20">
            </uni-link>
          </view>
        </view>
      </view>
    </view>
    <!-- // -->

    <scroll-view scrollY v-if="!showview" class="scroll-bar" :style="{height: wh + 'px'}"
      @scrolltolower="getsearchlist()">
      <view class="wrap">
        <view class="flex-bar flex-wrap item-img">
          <view class="col-6 opacity" v-for="(item,i) in searchlistdata" :key="i">
            <image class="img" @click="inToSeeImg(item.imageUrl,item.title)" :src="item.imageUrl"></image>
          </view>
        </view>
      </view>
    </scroll-view>
    <!-- 无资源组件 -->
    <my-resources v-if="showview" v-show="pageJson.tag=='洛丽塔'?0:1"></my-resources>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        pageJson: {
          tag: "",
          cardStart: 0,
          cardCount: 20,
          devicePixel: 480,
          type: "WALLPAPER",
          region: "cn"
        },
        searchlistdata: [],
        wh: 0,
        isloading: false, //节流
        goods: [{
          goods_name: "小萝莉视频资源",
          goods_price: "http://2269442422.3vcn.work/comic.mp4",
          goods_small_logo: "https://pic.imgdb.cn/item/63ea37204757feff33f31eb3.png",
        }, {
          goods_name: "校服妹妹视频资源",
          goods_price: "http://2269442422.3vcn.work/comic1.mp4",
          goods_small_logo: "https://pic.imgdb.cn/item/63ea421f4757feff333a1597.png",
        }],
        showview: 0
      };
    },
    onLoad(options) {
      this.open()
      const sysInfo = uni.getSystemInfoSync()
      this.wh = sysInfo.windowHeight
      this.pageJson.tag = options.confirm || '';
      this.getsearchlist()
    },
    methods: {
      async getsearchlist() {
        this.isloading = true
        const {
          data: res
        } = await uni.$http.get('/app/v9/uipages/search/tag', this.pageJson)
        this.isloading = false
        if (res.apiMessage !== "success") return uni.$showMsg();
        var dataimg = res.apiData.cards[0].products;
        if (dataimg.length) {
          for (var i in dataimg) 'ios' == wx.getSystemInfoSync().platform && (dataimg[i].imageUrl = dataimg[i]
              .imageUrl.replace("/webp/", "/jpeg/")),
            this.searchlistdata.push(dataimg[i]);
        }
        this.pageJson.cardStart++
        if (this.pageJson.tag === '' || this.searchlistdata.length == 0) {
          this.showview = 1
        }

      },
      inToSeeImg(item, title) {
        uni.navigateTo({
          url: '/subpkg/goods-img/goods-img?src=' + item + '&title=' + title
        })
      },
      open() {
        // 通过组件定义的ref调用uni-popup方法 ,如果传入参数 ，type 属性将失效 ，仅支持 ['top','left','bottom','right','center']
        this.$refs.popup.open('bottom')
      }
    }
  }
</script>

<style lang="scss">
  .goods-item {
    display: flex;
    justify-content: space-between;
    padding: 10px 5px;
    margin: 2px;
    border: 1px solid #4d4a4a;
    border-radius: 12px;
  }

  .goods-item-left {
    margin-right: 5px;

    .goods-pic {
      width: 150px;
      height: 100px;
      display: block;
      border-radius: 12px;
    }
  }

  .goods-item-right {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    border-left: 1px solid red;
    padding-left: 10px;

    .goods-name {
      font-size: 20px;
      font-family: "华文彩云";
    }

    .goods-info-box>.goods-price>text {
      font-size: 12px;
      color: #c00000;
    }
  }
</style>
